package graph_viewer.util;

import java.util.*;

import graph_viewer.canvas.*;
import graph_viewer.experiment.*;
import graph_viewer.structure.*;

/**
 * define a file reader methods
 */

public class Experiment_Util{
	static public String generate_result_file_name( Drawer_Canvas a_dc ){
		String result_file_name	=  Experiment.dir + a_dc.get_layout_adjuster().get_name() + "_" + Experiment.expriment_result;	

		return result_file_name;
	} 

	//randomly pick a focus from focus_candidates
	static public Node pick_a_focus( Drawer_Canvas a_dc ){
		ArrayList focus_candidates	= find_focus_candidates( a_dc );
		
		Node picked_focus;

		int size	= focus_candidates.size();
		Debug.println( "focus_candidates size: " + size, 43 );



		if ( size	== 0 ){
			picked_focus = null;
		}else{
			double random	= Math.random(); 
			Debug.println( "random is: " + random, 43 );

			int position	= (int )(random * size);
			Debug.println( "picked_focus randomly: position: " + position, 43 );
			picked_focus	= (Node)focus_candidates.get( position );
		}

		Debug.println( "picked_focus " + picked_focus, 43 );
		
		return picked_focus;
	}
	
	//a focus candidate is: displayed && !root && !leaf, && !psuedo && !focus
	static private ArrayList find_focus_candidates( Drawer_Canvas a_dc ){
		Graph a_graph		= a_dc.get_graph();
		Node current_focus	= a_dc.get_canvas_metrics().get_focus();

		ArrayList focus_candidates	= new ArrayList();

		ArrayList displayed_nodes	= a_graph.find_displayed_nodes();
	
		for ( Iterator _i = displayed_nodes.iterator(); _i.hasNext(); ){
			Node a_displayed_node	= (Node)_i.next();

			if ( a_displayed_node.is_leaf_cluster() 
				&& !a_displayed_node.is_leaf() 
				&& !a_displayed_node.get_is_psuedo() )
			{
				focus_candidates.add( a_displayed_node );
			}
		}
		
		Debug.println( "focus_candidates: " + focus_candidates, 43);

		return focus_candidates;
	}
}

